<!--
 * @Description: 基础告警配置
-->
<template>
  <div style="width: 100%; height: 100%; position: relative">
    <!-- 合并基础、告警模板配置、告警类别管理
    <div class="selectbut" :style="{ top: topStyle }">
      <selectbut :buttonselectlist="selectbutlist" @nowselectbuttonindex="gettabletype" />
    </div> -->
    <BaseMainSlot v-if="state == 0" :show-tab="true" :show-search-box="false">
      <template v-slot:btn-box>
        <ActionBar
          :page-no="21"
          :add-active="addActive"
          :del-active="delActive"
          :edit-active="editActive"
          :cancel-active="cancelActive"
          :has-cancel="false"
          :has-save="false"
          :has-edit="false"
          :save-active="saveActive"
          :has-edit-column="true"
          @showColumn="showColumn"
          @add="add('formData')"
          @cancel="cancel"
          @edit="edit"
          @del="del"
          @save="save"
        />
      </template>
      <template v-slot:table-box>
        <Table v-loading="loading" :prop-list="tableColumn" :list-data="tableData" @handleSelectionChange="handleSelectionChange">
          <template v-slot:operation="{ row }">
            <template v-if="!row.index">
              <el-button class="text-btn-cursor" type="text" size="small" @click="dbHandleSee(row)"><i class="el-icon-view"></i> 查看</el-button>
              <el-button class="text-btn-cursor" type="text" size="small" @click="edit(row)"><i class="el-icon-edit-outline"></i> 修改</el-button>
              <el-button class="text-btn-cursor cursor-delete" type="text" size="small" @click="handleDelete(row)"><i class="el-icon-delete"></i> 删除</el-button>
            </template>
          </template>
        </Table>
        <Pagination :page-size="pageSize" :current-page="currentPage" :total-size="totalSize" @changePageSize="changePageSize" @changeCurrentPage="changeCurrentPage" />
      </template>
      <template v-slot:dialog>
        <el-dialog :title="titleText + '基础告警配置'" :visible.sync="dialogFormVisible" width="40%" @close="cancel('formData')">
          <el-form ref="formData" label-position="left" :model="formData" :rules="rules" class="el-form">
            <el-form-item v-if="nowChanceStau === 'add'" label="模板选择:" class="w50p">
              <el-select v-model="nowalarmTemplateId" :disabled="!canInput" clearable @change="chancetemple">
                <el-option v-for="(item, index) in alarmTemplatelist" :key="index" :value="item.alarmTemplateId" :label="item.templateName" />
              </el-select>
            </el-form-item>
            <el-form-item label="批次选择:" class="w50p" prop="batchNo">
              <el-select v-model="formData.batchNo" :disabled="!canInput" clearable filterable placeholder="请选择批次">
                <el-option v-for="(item, index) in batchList" :key="index" :value="item.batchNo" :label="item.batchName" />
              </el-select>
              <!-- 没有，要改 -->
              <!-- <el-input v-model="formData.batchName" />
            <el-input v-model="formData.batchNo" /> -->
            </el-form-item>
            <el-form-item label="告警名称:" class="w50p" prop="baseAlarmName">
              <el-input v-model="formData.baseAlarmName" :disabled="!canInput" />
            </el-form-item>
            <el-form-item label="监测数据项:" class="w50p" prop="dataItemId">
              <el-select v-model="formData.dataItemId" :disabled="!canInput" filterable clearable :placeholder="formData.dataItemName" @change="chandataitem">
                <el-option v-for="(item, index) in dataitemlist" :key="index" :value="item.dataItemId" :label="item.originalName" />
              </el-select>
            </el-form-item>
            <!-- <el-form-item label="模板名称" class="w50p">
            <el-input
              v-model="formData.templateName"
              :disabled="!canInput"
              clearable
            />
          </el-form-item> -->
            <el-form-item label="发送间隔(分钟):" class="w50p" prop="sendingInterval">
              <el-input v-model="formData.sendingInterval" :disabled="!canInput" clearable />
            </el-form-item>
            <el-form-item label="告警通知配置:" class="w50p" prop="noticeConfigNo">
              <el-select v-model="formData.noticeConfigNo" clearable>
                <!-- @change="tifierChange" -->
                <el-option v-for="(item, index) in contactmanList" :key="index" :value="item.noticeConfigNo" :label="item.noticeConfigName" />
              </el-select>
            </el-form-item>
            <el-form-item label="滤波类型:" class="w50p" prop="filterType">
              <el-select v-model="formData.filterType" :disabled="!canInput" clearable placeholder="请选择">
                <el-option v-for="(item, index) in filterTypeList" :key="index" :value="item.name" :label="item.name" />
              </el-select>
            </el-form-item>
            <el-form-item label="滤波值:" class="w50p" prop="filterValue">
              <el-input v-model="formData.filterValue" :disabled="!canInput" clearable />
            </el-form-item>
            <el-form-item label="上限列表:" class="w100p">
              <div
                v-if="
                  nowChanceStau === 'add' ||
                    nowChanceStau === 'edit'
                "
              >
                <div class="line">
                  <el-input v-model="basetopList.levelName" :disabled="!canInput" clearable placeholder="级别名称" />
                  <el-input v-model="basetopList.thresholdValue" type="number" :disabled="!canInput" clearable placeholder="级别阈值" />
                  <el-select v-model="basetopList.alarmTypeId">
                    <el-option v-for="(item, index) in alarmTypeList" :key="index" :label="item.alarmTypeName" :value="item.alarmTypeId" />
                  </el-select>
                  <div class="line-click" @click="addtopList()">
                    <i class="el-icon-plus"></i>
                  </div>
                </div>
                <div v-for="(item, index) in nowtopList" :key="index" class="line">
                  <el-input v-model="nowtopList[index].levelName" :disabled="!canInput" clearable placeholder="级别名称" />
                  <el-input v-model="nowtopList[index].thresholdValue" type="number" :disabled="!canInput" clearable placeholder="级别阈值" />
                  <el-select v-model="nowtopList[index].alarmTypeId">
                    <el-option v-for="(alarmTypeitem, alarmTypeindex) in alarmTypeList" :key="alarmTypeindex" :label="alarmTypeitem.alarmTypeName" :value="alarmTypeitem.alarmTypeId" />
                  </el-select>
                  <div class="line-click" @click="deltopList(index)">
                    <i class="el-icon-minus"></i>
                  </div>
                </div>
              </div>
            </el-form-item>
            <el-form-item label="下限列表:" class="w100p">
              <div
                v-if="
                  nowChanceStau === 'add' ||
                    nowChanceStau === 'edit'
                "
              >
                <div class="line">
                  <el-input v-model="basebottomList.levelName" :disabled="!canInput" clearable placeholder="级别名称" />
                  <el-input v-model="basebottomList.thresholdValue" type="number" :disabled="!canInput" clearable placeholder="级别阈值" />
                  <el-select v-model="basebottomList.alarmTypeId">
                    <el-option v-for="(item, index) in alarmTypeList" :key="index" :label="item.alarmTypeName" :value="item.alarmTypeId" />
                  </el-select>
                  <div class="line-click" @click="addbottomList()">
                    <i class="el-icon-plus"></i>
                  </div>
                </div>
                <div v-for="(item, index) in nowbottomList" :key="index" class="line">
                  <el-input v-model="nowbottomList[index].levelName" :disabled="!canInput" clearable placeholder="级别名称" />
                  <el-input v-model="nowbottomList[index].thresholdValue" type="number" :disabled="!canInput" clearable placeholder="级别阈值" />
                  <el-select v-model="nowbottomList[index].alarmTypeId">
                    <el-option v-for="(alarmTypeitem, alarmTypeindex) in alarmTypeList" :key="alarmTypeindex" :label="alarmTypeitem.alarmTypeName" :value="alarmTypeitem.alarmTypeId" />
                  </el-select>
                  <div class="line-click" @click="delbottomList(index)">
                    <i class="el-icon-minus"></i>
                  </div>
                </div>
              </div>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button class="zh-button-one" @click="cancel"> 取 消 </el-button>
            <el-button class="zh-button-two" type="primary" @click="save('formData')">
              保 存
            </el-button>
          </div>
        </el-dialog>
        <el-dialog :title="'查看' + '基础告警配置'" :visible.sync="dialogeSeeFormVisible" width="40%" @close="cancel1">
          <el-form ref="formData1" label-position="left" :model="formData1" :rules="rules" class="el-form">
            <el-form-item label="批次选择:" class="w50p" prop="nowbatch">
              <el-select v-model="formData1.batchNo" :disabled="!canInput" clearable filterable:placeholder="formData.batchName">
                <el-option
                  v-for="(item, index) in batchList"
                  :key="index"
                  :value="item.batchNo"
                  :label="item.batchName"
                />
              </el-select>
              <!-- 没有，要改 -->
              <!-- <el-input v-model="formData.batchName" />
            <el-input v-model="formData.batchNo" /> -->
            </el-form-item>
            <el-form-item label="告警名称:" class="w50p" prop="baseAlarmName">
              <el-input v-model="formData1.baseAlarmName" disabled />
            </el-form-item>
            <el-form-item label="监测数据项:" class="w50p">
              <el-select v-model="formData1.dataItemId" disabled filterable clearable :placeholder="formData.dataItemName">
                <el-option v-for="(item, index) in dataitemlist" :key="index" :value="index" :label="item.originalName" />
              </el-select>
            </el-form-item>
            <el-form-item label="发送间隔:" class="w50p" prop="sendingInterval">
              <el-input v-model="formData1.sendingInterval" disabled clearable />
            </el-form-item>
            <el-form-item label="滤波类型:" class="w50p" prop="filterType">
              <el-select v-model="formData1.filterType" disabled clearable :placeholder="formData.filterType">
                <el-option v-for="(item, index) in filterTypeList" :key="index" :value="item.name" :label="item.name" />
              </el-select>
            </el-form-item>
            <el-form-item label="滤波值:" class="w50p" prop="filterValue">
              <el-input v-model="formData1.filterValue" disabled clearable />
            </el-form-item>
            <el-form-item label="告警联系人:" class="w50p" prop="noticeConfigNo">
              <el-select v-model="formData1.noticeConfigNo" disabled clearable>
                <!-- @change="tifierChange" -->
                <el-option v-for="(item, index) in contactmanList" :key="index" :value="item.noticeConfigNo" :label="item.noticeConfigName" />
              </el-select>
            </el-form-item>
            <el-form-item label="上限列表:" class="w100p">
              <div>
                <div class="line">
                  <el-input v-model="basetopList.levelName" disabled clearable placeholder="级别名称" />
                  <el-input v-model="basetopList.thresholdValue" disabled clearable placeholder="级别阈值" />
                  <el-select v-model="basetopList.alarmTypeId" disabled>
                    <el-option v-for="(item, index) in alarmTypeList" :key="index" :label="item.alarmTypeName" :value="item.alarmTypeId" />
                  </el-select>
                  <!-- <div class="line-click" @click="addtopList()">
                  <i class="el-icon-plus"></i>
                </div> -->
                </div>
                <div v-for="(item, index) in nowtopList" :key="index" class="line">
                  <el-input v-model="nowtopList[index].levelName" disabled clearable placeholder="级别名称" />
                  <el-input v-model="nowtopList[index].thresholdValue" disabled clearable placeholder="级别阈值" />
                  <el-select v-model="nowtopList[index].alarmTypeId" disabled>
                    <el-option v-for="(alarmTypeitem, alarmTypeindex) in alarmTypeList" :key="alarmTypeindex" :label="alarmTypeitem.alarmTypeName" :value="alarmTypeitem.alarmTypeId" />
                  </el-select>
                  <div class="line-click" @click="deltopList(index)">
                    <i class="el-icon-minus"></i>
                  </div>
                </div>
              </div>
            </el-form-item>
            <el-form-item label="下限列表:" class="w100p">
              <div>
                <div class="line">
                  <el-input v-model="basebottomList.levelName" disabled clearable placeholder="级别名称" />
                  <el-input v-model="basebottomList.thresholdValue" disabled clearable placeholder="级别阈值" />
                  <el-select v-model="basebottomList.alarmTypeId" disabled>
                    <el-option v-for="(item, index) in alarmTypeList" :key="index" :label="item.alarmTypeName" :value="item.alarmTypeId" />
                  </el-select>
                  <!-- <div class="line-click" @click="addbottomList()">
                  <i class="el-icon-plus"></i>
                </div> -->
                </div>
                <div v-for="(item, index) in nowbottomList" :key="index" class="line">
                  <el-input v-model="nowbottomList[index].levelName" disabled clearable placeholder="级别名称" />
                  <el-input v-model="nowbottomList[index].thresholdValue" disabled clearable placeholder="级别阈值" />
                  <el-select v-model="nowbottomList[index].alarmTypeId" disabled>
                    <el-option v-for="(alarmTypeitem, alarmTypeindex) in alarmTypeList" :key="alarmTypeindex" :label="alarmTypeitem.alarmTypeName" :value="alarmTypeitem.alarmTypeId" />
                  </el-select>
                  <div class="line-click" @click="delbottomList(index)">
                    <i class="el-icon-minus"></i>
                  </div>
                </div>
              </div>
            </el-form-item>
          </el-form>
          <div v-if="nowChanceStau !== ''" slot="footer" class="dialog-footer">
            <el-button class="zh-button-one" @click="cancel"> 取 消 </el-button>
            <el-button class="zh-button-two" type="primary" @click="save('formData')">
              保 存
            </el-button>
          </div>
        </el-dialog>
        <el-dialog id="tableColumnDialog" title="配置列" :visible.sync="dialogTableColumnVisible">
          <tableColumn v-if="dialogTableColumnVisible" ref="tableColumn" :table-column="allTableColumn" @cancelColumn="cancelColumn" />
          <div slot="footer" class="dialog-footer">
            <el-button class="zh-button-one" @click="dialogTableColumnVisible = false">
              取 消
            </el-button>
            <el-button class="zh-button-two" type="primary" @click="saveColumn">
              保 存
            </el-button>
          </div>
        </el-dialog>
      </template>
    </BaseMainSlot>
  </div>
</template>

<script>
import Table from '@/components/table/table.vue'
import ActionBar from '@/components/ActionBar'
import Pagination from '@/components/Pagination'
import nowpagereq from '@/api/digital-production/monitoring-alarm/basic-alarm-configuration'
import userreq from '@/api/user/index'
// import contactreq from "@/api/digital-production/monitoring-alarm/alarm-contact-management"
import contactnot from '@/api/digital-production/monitoring-alarm/system-notification-configuration'
import selectbut from '@/components/selectbutton/index.vue'
import BaseMainSlot from '@/components/BaseMainSlot/newBaseMainSlot.vue'
import { mymixin } from '@/utils/mixins'
import { mapGetters } from 'vuex'
import alarmCategoryManagement from '@/views/digital-production/monitoring-alarmManagement/alarm-category-management'
import alarmTemplateConfiguration from '@/views/digital-production/monitoring-alarmManagement/alarm-template-configuration'
export default {
  name: 'BasicAlarmConfiguration',
  components: {
    Table,
    ActionBar,
    Pagination,
    BaseMainSlot,
    selectbut,
    alarmCategoryManagement,
    alarmTemplateConfiguration
  },
  mixins: [mymixin],
  data() {
    return {
      topStyle: '7px',
      state: 0,
      tableColumn: [
        { prop: 'batchName', label: '批次名称', minWidth: '300' },
        { prop: 'baseAlarmName', label: '告警名称', minWidth: '300' },
        { prop: 'dataItemName', label: '告警数据项', minWidth: '150' },
        { prop: 'dataTypeName', label: '告警数据类型', minWidth: '150' },
        { prop: 'dataItemName', label: '监测数据项', minWidth: '150' },
        {
          prop: 'operation',
          label: '操作',
          slotName: 'operation',
          width: '200'
        }
      ],
      rules: {
        baseAlarmName: [
          {
            required: true,
            message: '请输入告警名称',
            trigger: ['change', 'blur']
          },
          { min: 3, max: 20, message: '长度在 3 到 20 个字符', trigger: 'blur' }
        ],
        sendingInterval: [
          {
            required: true,
            message: '请输入发送间隔',
            trigger: ['change', 'blur']
          }
        ],
        dataItemId: [
          {
            required: true,
            message: '请选择监测数据项目',
            trigger: ['change', 'blur']
          }
        ],
        noticeConfigNo: [
          {
            required: true,
            message: '请选择告警通知配置',
            trigger: ['change', 'blur']
          }
        ],
        filterType: [
          {
            required: true,
            message: '请选择滤波类型',
            trigger: ['change', 'blur']
          }
        ],
        filterValue: [
          {
            required: true,
            message: '请输入滤波值',
            trigger: ['change', 'blur']
          }
        ],
        batchNo: [
          { required: true, message: '请选择批次', trigger: ['change', 'blur'] }
        ]
      },
      // 数值告警时
      // 数据项
      dataitemtwoindex: '',
      dataitemtwoname: '',
      dataitemtwolist: [],
      // 设施
      facilitytwoIndex: '',
      facilitytwoname: '',
      facilitylist: [],
      // 选择类型
      // selectbutlist: [
      //   { name: '基础告警配置' },
      //   { name: '告警类别管理' },
      //   { name: '告警模板配置' }
      // ],
      dataitemlist: [],
      // 告警模板
      nowalarmTemplateId: '',
      alarmTemplatelist: [],
      // 批次
      batchList: [],
      nowbatch: {},
      // 主要联系人
      zhuyaocontactmanId: '',
      checkedGroupone: [],
      // 其他联系人
      qitacontactmanId: '',
      checkedGrouptwo: [],
      // 联系人可选择列表
      contactmanList: [],
      // 联系方式可选择列表
      contactmetList: [
        {
          name: '手机'
        },
        {
          name: '邮箱'
        },
        {
          name: '微信'
        }
      ],
      // 上限列表
      basetopList: {
        levelName: '',
        alarmTypeId: '',
        thresholdType: 'max',
        thresholdValue: ''
      },
      nowtopList: [],
      // 下限列表
      basebottomList: {
        alarmTypeId: '',
        levelName: '',
        thresholdType: 'min',
        thresholdValue: ''
      },
      nowbottomList: [],
      filterTypeList: [
        {
          name: '时间'
        },
        {
          name: '次数'
        }
      ],
      // 数据类别
      // nowdataType: {},
      // dataTypeList: [],
      // 告警类型下拉数据
      alarmTypeList: [],
      // 搜索内容
      searchList: {},
      // 选中的数据项数组 alarmContactId组成 (此数组最多为一个)
      selectIdList: [],
      dialogTitle: '',
      canInput: false,
      dialogeSeeFormVisible: false,
      dialogFormVisible: false,
      formData: {
        baseAlarmName: '',
        sendingInterval: '',
        filterValue: '',
        noticeConfigNo: '',
        batchName: '',
        batchNo: ''
      },
      formData1: {
        baseAlarmName: '',
        sendingInterval: '',
        filterValue: '',
        noticeConfigNo: '',
        batchName: '',
        batchNo: ''
      },
    }
  },
  computed: {
    ...mapGetters({
      judgePermission: 'permission/judgePermission'
    })
  },
  watch: {},
  created() {
    // 获取表格数据
    this.getTableDataList()
  },
  mounted() {
    this.getselectlist()
  },
  methods: {
    handleAdd() {
      // 上限列表和下限列表清空
      this.basetopList = {
        levelName: '',
        alarmTypeId: '',
        thresholdType: 'max',
        thresholdValue: ''
      }
      this.nowtopList = []
      this.basebottomList = {
        levelName: '',
        alarmTypeId: '',
        thresholdType: 'min',
        thresholdValue: ''
      }
      this.nowbottomList = []
    },
    cancel1() {
      this.formData = {}
      this.formData1 = {}
      this.nowtopList = []
      this.nowbottomList = []
    },
    changeTableSort(column) {
      this.sortList = column.order
        ? [
          {
            property: column.prop,
            direction: column.order == 'ascending' ? 'asc' : 'desc'
          }
        ]
        : []
      this.getTableDataList()
    },
    // 选择数值告警时，
    // 选择数据选择方法
    chancedataitemmethodtwo(i) {
      let mes = this.dataitemtwolist[i]
      this.formData.dataItemId = mes.dataItemId
      this.formData.dataItemName = mes.dataItemName
      this.formData.dataTypeId = mes.dataTypeId
      this.formData.dataTypeName = mes.dataTypeName
    },
    // 选择设施
    chancefacilitymethodtwo(i) {
      let mes = this.facilitylist[i]
      this.formData.facilityId = mes.facilityId
      this.formData.facilityName = mes.facilityName
      this.formData.farmingTypeNo = mes.farmingTypeNo
      this.formData.organizationNo = mes.organizationNo
      this.getbyconditiondataitem({ facilityId: mes.facilityId })
    },
    // 选择模板
    chancetemple(e) {
      nowpagereq.getalarmTemplatemessagelist(e).then(res => {
        let row = res.data
        if (this.nowalarmTemplateId > 0) {
          this.chancetemplelist(row)
        }
      })
    },
    // 选择数据项
    chandataitem(i) {
      this.dataitemlist.forEach(el => {
        if (el.dataItemId === i) {
          this.formData['dataItemName'] = el.dataItemName
          this.formData['dataItemId'] = el.dataItemId
          this.formData['dataTypeId'] = el.dataTypeId
          this.formData['dataTypeName'] = el.dataTypeName
          if (el.enumListType) {
            let list = el.enumListType.split(';')
            list = list.filter(ele => {
              return ele && ele.trim()
            })
            let v = list[list.length - 1].split(':')
            this.basetopList.thresholdValue = v[0]
          }
        }
      })
    },
    // 选择模板时的数据处理
    chancetemplelist(zhrow) {
      console.log(zhrow)
      this.formData = {}
      let row = JSON.parse(JSON.stringify(zhrow))
      if (row.alarmTemplateId) {
        this.formData = {
          alarmTemplateId: row.alarmTemplateId,
          templateName: row.templateName,
          sendingInterval: row.sendingInterval,
          filterValue: row.filterValue,
          filterType: row.filterType,
          noticeConfigNo: row.noticeConfigNo,
          // dataTypeId: row.dataTypeId,
          // dataTypeName: row.dataTypeName
        }
        nowpagereq.getalarmTypelist(row.dataTypeId).then(res => {
          let data = res.data
          this.chancealarmtype(data)
        })
        // this.nowdataType = {
        //   value: row.dataTypeId,
        //   name: row.dataTypeName
        // }
        row.alarmTemplateThresholdList.forEach(item => {
          if (item.charge === true) {
            this.zhuyaocontactmanId = item.alarmContactId
            // 联系方式的赋值
            this.checkedGroupone = []
            if (item.sendPhone === true) {
              this.checkedGroupone.push(0)
            }
            if (item.sendEmail === true) {
              this.checkedGroupone.push(1)
            }
            if (item.sendWeChat === true) {
              this.checkedGroupone.push(2)
            }
          }
          if (item.charge === false) {
            this.qitacontactmanId = item.alarmContactId
            // 联系方式的赋值
            this.checkedGrouptwo = []
            if (item.sendPhone === true) {
              this.checkedGrouptwo.push(0)
            }
            if (item.sendEmail === true) {
              this.checkedGrouptwo.push(1)
            }
            if (item.sendWeChat === true) {
              this.checkedGrouptwo.push(2)
            }
          }
        })
        let mainlist = row.alarmTemplateThresholdList
        // 上限列表和下限列表的赋值
        this.basetopList = {
          levelName: '',
          alarmTypeId: '',
          thresholdType: 'max',
          thresholdValue: ''
        }
        this.nowtopList = []
        this.basebottomList = {
          levelName: '',
          alarmTypeId: '',
          thresholdType: 'min',
          thresholdValue: ''
        }
        this.nowbottomList = []
        for (var i = 0; i < mainlist.length; i++) {
          if (mainlist[i].thresholdType === 'max') {
            if (this.basetopList.levelName.length === 0) {
              this.basetopList = mainlist[i]
            } else {
              this.nowtopList.push(mainlist[i])
            }
          } else if (mainlist[i].thresholdType === 'min') {
            if (this.basebottomList.levelName.length === 0) {
              this.basebottomList = mainlist[i]
            } else {
              this.nowbottomList.push(mainlist[i])
            }
          }
        }
      }
    },
    // 添加一条上限数据
    addtopList() {
      let addvalue = {
        alarmTypeId: '',
        levelName: '',
        thresholdType: 'max',
        thresholdValue: ''
      }
      this.nowtopList.push(addvalue)
    },
    // 删除一条上限数据
    deltopList(i) {
      this.nowtopList.splice(i, 1)
    },
    // 添加一条下限数据
    addbottomList() {
      let addvalue = {
        alarmTypeId: '',
        levelName: '',
        thresholdType: 'min',
        thresholdValue: ''
      }
      this.nowbottomList.push(addvalue)
    },
    // 添加一条下限数据
    delbottomList(i) {
      this.nowbottomList.splice(i, 1)
    },
    // 查看
    dbHandleSee(row) {
      this.formData = {}
      this.formData1 = {}
      if (this.nowselecttype === 1) {
        this.formData1 = row
        this.dataitemtwoname = row.dataItemName
        this.facilitytwoname = row.facilityName
        // this.openDialog('edit');
        return
      }
      // 下面时物联自动告警
      if (row.baseAlarmId) {
        this.formData1 = {
          baseAlarmId: row.baseAlarmId,
          baseAlarmName: row.baseAlarmName,
          sendingInterval: row.sendingInterval,
          filterValue: row.filterValue,
          filterType: row.filterType,
          dataItemName: row.dataItemName,
          dataItemId: row.dataItemId,
          dataTypeName: row.dataTypeName,
          dataTypeId: row.dataTypeId,
          batchNo: row.batchNo,
          batchName: row.batchName,
          nowalarmTemplateId: row.nowalarmTemplateId,
          noticeConfigNo: row.noticeConfigNo,
          batchNo: row.batchNo
        }
        this.nowalarmTemplateId = row.nowalarmTemplateId

        // this.nowdataType = {
        //   value: row.dataTypeId,
        //   name: row.dataTypeName
        // }
        this.addDataType({ name: row.dataTypeName, value: row.dataTypeId })
        let mainlist = row.baseAlarmThresholdList
        // 上限列表和下限列表的赋值
        this.basetopList = {
          levelName: '',
          alarmTypeId: '',
          thresholdType: 'max',
          thresholdValue: ''
        }
        this.nowtopList = []
        this.basebottomList = {
          levelName: '',
          alarmTypeId: '',
          thresholdType: 'min',
          thresholdValue: ''
        }
        this.nowbottomList = []
        for (var i = 0; i < mainlist.length; i++) {
          if (mainlist[i].thresholdType === 'max') {
            if (this.basetopList.levelName.length === 0) {
              this.basetopList = mainlist[i]
            } else {
              this.nowtopList.push(mainlist[i])
            }
          } else if (mainlist[i].thresholdType === 'min') {
            if (this.basebottomList.levelName.length === 0) {
              this.basebottomList = mainlist[i]
            } else {
              this.nowbottomList.push(mainlist[i])
            }
          }
        }
      }
      this.dialogeSeeFormVisible = true
    },
    // 获取下拉数据
    getselectlist() {
      // 获取设施下拉数据
      let faciparams = {}
      if (this.nowChanceStau === 'add') {
        faciparams = {
          organizationList: sessionStorage
            .getItem('organizationList')
            .split(','),
          farmingTypeNo: sessionStorage.getItem('farmingTypeNo'),
          facilityStatus: 1
        }
      } else {
        faciparams = {
          organizationList: sessionStorage
            .getItem('organizationList')
            .split(','),
          farmingTypeNo: sessionStorage.getItem('farmingTypeNo')
        }
      }
      userreq.getfacilityAll(faciparams).then(res => {
        this.facilitylist = res.data
      })
      // 获取批次列表 ---组织结构id跟着批次id
      nowpagereq.getbatchlist({simpleData: true}).then(res => {
        this.batchList = res.data
      })
      // 获取可选择模板
      nowpagereq.getalarmTemplatelist().then(res => {
        this.alarmTemplatelist = res.data
        this.chancetemple(this.alarmTemplatelist[0].alarmTemplateId)
      })
      // 获取所有监测数据项
      nowpagereq.getdataitemlist().then(res => {
        this.dataitemlist = res.data
      })
      // 获取所有联系人
      contactnot
        .querybycondition({ organizationNo: sessionStorage.organizationNo })
        .then(res => {
          this.contactmanList = res.data
        })
    },
    // 通过设施id获取数据dataitem
    getbyconditiondataitem(par) {
      nowpagereq.getdataitemlist(par).then(res => {
        this.dataitemtwolist = res.data
      })
    },
    // 将选择的数据类别添加到表单中 --获取告警类型列表
    addDataType(e) {
      if (this.nowChanceStau === 'add' || this.nowChanceStau === 'edit') {
        this.formData['dataTypeId'] = e.value
        this.formData['dataTypeName'] = e.name
      }
      nowpagereq.getalarmTypelist(e.value).then(res => {
        let data = res.data
        this.chancealarmtype(data)
      })
    },
    // 处理数据类型数据
    chancealarmtype(list) {
      let newlist = []
      list.forEach((item, index) => {
        newlist.push(item.alarmType)
      })
      this.alarmTypeList = newlist
      //   "data": [
      // {
      //   "alarmType": {
      //     "alarmTypeId": 1,
      //     "alarmTypeName": "高温告警",
      //     "organizationNo": 0,
      //     "system": "SC"
      //   },
      //   "alarmTypeDataTypeMapperId": 1,
      //   "alarmTypeId": 1,
      //   "dataTypeId": 1,
      //   "dataTypeName": "温度",
      //   "organizationNo": 1
      // }
      // ],
    },
    // 添加滤波类型
    addFilterType(e) {
      if (this.nowChanceStau === 'add' || this.nowChanceStau === 'edit') {
        this.formData.filterType = e.name
      }
    },
    // 获取表格数据
    getTableDataList() {
      // 拦截表格数据请求
      if (this.nowselecttype === 1) {
        this.getTableDataListtwo()
        return
      }
      this.loading = true
      let params = {
        page: this.currentPage,
        size: this.pageSize,
        sortList: this.sortList || []
      }
      nowpagereq.getlist(params).then(res => {
        this.loading = false
        if (res.code === 0) {
          this.$message.error('查询失败')
        }
        let data = res.data
        // 赋值总条数
        this.totalSize = data.totalElements
        // 赋值数组
        this.tableData = data.content
        this.addblankmet()
        this.resetActionBar()
      })
    },
    // 获取数值告警表格数据
    getTableDataListtwo() {
      this.loading = true
      let params = {
        page: this.currentPage,
        size: this.pageSize
      }
      nowpagereq.getDataItemtable(params).then(res => {
        this.loading = false
        if (res.code === 0) {
          this.$message.error('查询失败')
        }
        let data = res.data
        // 赋值总条数
        this.totalSize = data.totalElements
        // 赋值数组
        this.tableData = data.content
        this.addblankmet()
        this.resetActionBar()
      })
    },
    search() {
      this.currentPage = 1
      this.getTableDataList()
    },
    changePageSize(pageSize) {
      this.pageSize = pageSize
      this.getTableDataList()
    },
    changeCurrentPage(currentPage) {
      this.currentPage = currentPage
      this.getTableDataList()
    },
    handleEdit(zhrow) {
      this.formData = {}
      let row = JSON.parse(JSON.stringify(zhrow))
      if (this.nowselecttype === 1) {
        this.formData = row
        this.dataitemtwoname = row.dataItemName
        this.facilitytwoname = row.facilityName
        // this.openDialog('edit');
        return
      }
      // 下面时物联自动告警
      if (row.baseAlarmId) {
        this.formData = {
          baseAlarmId: row.baseAlarmId,
          baseAlarmName: row.baseAlarmName,
          sendingInterval: row.sendingInterval,
          filterValue: row.filterValue,
          filterType: row.filterType,
          dataItemName: row.dataItemName,
          dataItemId: row.dataItemId,
          dataTypeName: row.dataTypeName,
          dataTypeId: row.dataTypeId,
          batchNo: row.batchNo,
          batchName: row.batchName,
          nowalarmTemplateId: row.nowalarmTemplateId,
          noticeConfigNo: row.noticeConfigNo
        }
        this.nowalarmTemplateId = row.nowalarmTemplateId

        // this.nowdataType = {
        //   value: row.dataTypeId,
        //   name: row.dataTypeName
        // }
        this.addDataType({ name: row.dataTypeName, value: row.dataTypeId })
        let mainlist = row.baseAlarmThresholdList
        // 上限列表和下限列表的赋值
        this.basetopList = {
          levelName: '',
          alarmTypeId: '',
          thresholdType: 'max',
          thresholdValue: ''
        }
        this.nowtopList = []
        this.basebottomList = {
          levelName: '',
          alarmTypeId: '',
          thresholdType: 'min',
          thresholdValue: ''
        }
        this.nowbottomList = []
        for (var i = 0; i < mainlist.length; i++) {
          if (mainlist[i].thresholdType === 'max') {
            if (this.basetopList.levelName.length === 0) {
              this.basetopList = mainlist[i]
            } else {
              this.nowtopList.push(mainlist[i])
            }
          } else if (mainlist[i].thresholdType === 'min') {
            if (this.basebottomList.levelName.length === 0) {
              this.basebottomList = mainlist[i]
            } else {
              this.nowbottomList.push(mainlist[i])
            }
          }
        }
      }
      // this.openDialog('edit');
    },
    handleSelectionChange(list) {
      this.selectIdList = []
      let notvalue = true
      if (this.nowselecttype === 1) {
        this.selectIdList = list.map(item => {
          if (item.numericalAlarmId) {
            return item.numericalAlarmId
          } else {
            notvalue = false
            return ''
          }
        })
      } else { // else if (this.nowselecttype === 0)
        this.selectIdList = list.map(item => {
          if (item.baseAlarmId) {
            return item.baseAlarmId
          } else {
            notvalue = false
            return ''
          }
        })
      }
      if (notvalue === false) {
        this.$message.warning('不可选择空数据！')
        return
      }
      console.log(222, this.selectIdList)
      if (this.selectIdList.length > 0) this.delActive = true
      else this.delActive = false
    },
    delmessage() {
      if (this.nowselecttype === 1) {
        nowpagereq.delDataItem(this.selectIdList).then(res => {
          if (res.code === 1) {
            this.$message.success('删除成功')
            this.getTableDataList()
          } else {
            this.$message.error('删除失败')
          }
        })
        return
      }
      nowpagereq.dellist(this.selectIdList).then(res => {
        if (res.code === 1) {
          this.$message.success('删除成功')
          this.getTableDataList()
        } else {
          this.$message.error('删除失败')
        }
      })
    },
    handleDelete(data) {
      this.$confirm('此操作将永久删除该条数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        customClass: 'myClass'
      })
        .then(() => {
          if (this.nowselecttype === 1) {
            nowpagereq.delDataItem([data.numericalAlarmId]).then(res => {
              if (res.code === 1) {
                this.$message.success('删除成功')
                this.getTableDataList()
              } else {
                this.$message.error('删除失败')
              }
            })
            return
          }
          nowpagereq.dellist([data.baseAlarmId]).then(res => {
            if (res.code === 1) {
              this.$message.success('删除成功')
              this.getTableDataList()
            } else {
              this.$message.error('删除失败')
            }
          })
        })
        .catch(() => {
          this.$message('取消删除')
        })
    },
    save() {
      this.$refs.formData.validate(valid => {
        if (valid) {
          if (this.nowChanceStau === 'edit') {
            if (this.nowselecttype === 1) {
              let editparamstwo = {
                ...this.formData,
                system: 'SC'
              }
              nowpagereq.editDataItem(editparamstwo).then(res => {
                if (res.code === 1) {
                  this.$message.success('修改成功！')
                  this.closeDialog()
                  this.getTableDataList()
                } else {
                  this.$message.error('修改失败！')
                }
              })
              return
            }
            let editparams = {
              // baseAlarmSendMapperList: [
              //   // 主要联系人
              //   {
              //     alarmContactId: this.zhuyaocontactmanId,
              //     alarmCharge: true,
              //     sendPhone: false,
              //     sendEmail: false,
              //     sendWeChat: false
              //   },
              //   // 其他联系人
              //   {
              //     alarmContactId: this.qitacontactmanId,
              //     alarmCharge: false,
              //     sendPhone: false,
              //     sendEmail: false,
              //     sendWeChat: false
              //   }
              // ],
              baseAlarmThresholdList: [
                // 上限数据
                this.basetopList,
                ...this.nowtopList,
                // 下限数据
                this.basebottomList,
                ...this.nowbottomList
              ],
              // 下面时一些与其他数据
              // filterType: this.formData.name,
              // dataTypeName: this.nowdataType.name,
              // dataTypeId: this.nowdataType.value,
              ...this.formData
            }
            // if (this.nowdataType.length > 0) {
            //   this.formData.dataTypeName = this.nowdataType.name
            //   this.formData.dataTypeId = this.nowdataType.value
            // }
            // editparams
            // 联系方式
            if (this.checkedGroupone.length > 0) {
              if (this.checkedGroupone.indexOf(0) > -1) {
                editparams.baseAlarmSendMapperList[0].sendPhone = true
              }
              if (this.checkedGroupone.indexOf(1) > -1) {
                editparams.baseAlarmSendMapperList[0].sendEmail = true
              }
              if (this.checkedGroupone.indexOf(2) > -1) {
                editparams.baseAlarmSendMapperList[0].sendWeChat = true
              }
            }
            if (this.checkedGrouptwo.length > 0) {
              if (this.checkedGrouptwo.indexOf(0) > -1) {
                editparams.baseAlarmSendMapperList[1].sendPhone = true
              }
              if (this.checkedGrouptwo.indexOf(1) > -1) {
                editparams.baseAlarmSendMapperList[1].sendEmail = true
              }
              if (this.checkedGrouptwo.indexOf(2) > -1) {
                editparams.baseAlarmSendMapperList[1].sendWeChat = true
              }
            }
            // 编辑接口
            nowpagereq.editlist(editparams).then(res => {
              if (res.code === 1) {
                this.$message.success('修改成功！')
                this.closeDialog()
                this.getTableDataList()
              } else {
                this.$message.error('修改失败！')
              }
            })
          } else if (this.nowChanceStau === 'add') {
            if (this.nowselecttype === 1) {
              let addparamstwo = {
                ...this.formData,
                system: 'SC'
              }
              nowpagereq.addDataItem(addparamstwo).then(res => {
                if (res.code === 1) {
                  this.$message.success('新增成功！')
                  this.closeDialog()
                  this.getTableDataList()
                } else {
                  this.$message.error('新增失败！')
                }
              })
              return
            }
            let addparams = {
              // baseAlarmSendMapperList: [
              //   // 主要联系人
              //   {
              //     alarmContactId: this.zhuyaocontactmanId,
              //     alarmCharge: true,
              //     sendPhone: false,
              //     sendEmail: false,
              //     sendWeChat: false
              //   },
              //   // 其他联系人
              //   {
              //     alarmContactId: this.qitacontactmanId,
              //     alarmCharge: false,
              //     sendPhone: false,
              //     sendEmail: false,
              //     sendWeChat: false
              //   }
              // ],
              baseAlarmThresholdList: [
                // 上限数据
                this.basetopList,
                ...this.nowtopList,
                // 下限数据
                this.basebottomList,
                ...this.nowbottomList
              ],
              alarmCharge: '', // 告警联系人名字
              // 下面时一些与其他数据
              // dataTypeName: this.nowdataType.name,
              // dataTypeId: this.nowdataType.value,
              ...this.formData
            }
            // // 通过id查告警联系人名字
            // nowpagereq.getalarmCharge(this.zhuyaocontactmanId).then(
            //   res => {
            //     addparams.alarmCharge = res.data.alarmContactName
            //   }
            // )
            // ---
            // if (this.nowdataType.length > 0) {
            //   this.formData.dataTypeName = this.nowdataType.name
            //   this.formData.dataTypeId = this.nowdataType.value
            // }
            // 联系方式
            if (this.checkedGroupone.length > 0) {
              if (this.checkedGroupone.indexOf(0) > -1) {
                addparams.baseAlarmSendMapperList[0].sendPhone = true
              }
              if (this.checkedGroupone.indexOf(1) > -1) {
                addparams.baseAlarmSendMapperList[0].sendEmail = true
              }
              if (this.checkedGroupone.indexOf(2) > -1) {
                addparams.baseAlarmSendMapperList[0].sendWeChat = true
              }
            }
            if (this.checkedGrouptwo.length > 0) {
              if (this.checkedGrouptwo.indexOf(0) > -1) {
                addparams.baseAlarmSendMapperList[1].sendPhone = true
              }
              if (this.checkedGrouptwo.indexOf(1) > -1) {
                addparams.baseAlarmSendMapperList[1].sendEmail = true
              }
              if (this.checkedGrouptwo.indexOf(2) > -1) {
                addparams.baseAlarmSendMapperList[1].sendWeChat = true
              }
            }
            // ---
            // console.log(addparams)
            // 需要删除
            addparams.organizationNo = sessionStorage.organizationNo
            this.batchList.forEach(el => {
              if (el.batchNo === addparams.batchNo) {
                addparams['batchName'] = el.batchName
              }
            })
            // console.log(addparams); return
            setTimeout(() => {
              if (!addparams.filterType) addparams.filterType = ''
              nowpagereq.addlist(addparams).then(res => {
                if (res.code === 1) {
                  this.$message.success('新增成功！')
                  this.closeDialog()
                  this.getTableDataList()
                } else {
                  this.$message.error(res.msg || '新增失败！')
                }
              })
            }, 200)
          }
        } else {
          return false
        }
      })
    },
    openDialog(type) {
      this.dialogFormVisible = true
      this.dialogTitle = type === 'add' ? '新增' : '编辑'
      this.nowChanceStau = type
    },
    closeDialog() {
      this.dialogTitle = null
      this.nowChanceStau = ''
      this.formData = {}
      this.nowbatch = ''
      this.basetopList = {
        levelName: '',
        alarmTypeId: '',
        thresholdType: 'max',
        thresholdValue: ''
      }
      this.basebottomList = {
        alarmTypeId: '',
        levelName: '',
        thresholdType: 'min',
        thresholdValue: ''
      }
      this.nowalarmTemplateId = ''
      this.nowbatch = ''
      this.nowalarmTemplateId = ''
      this.$nextTick(() => {
        this.$refs.formData.resetFields()
        // this.formData = { ...this.formData }
      })
      this.dialogFormVisible = false
    },
    // ----告警配置切换
    // gettabletype(i) {
    //   this.state = i
    //   this.nowselecttype = i
    //   this.formData = {}
    //   if (i === 0) {
    //     this.getTableDataList()
    //     this.topStyle = '7px'
    //   } else if (i === 1) {
    //     this.getTableDataListtwo()
    //     this.topStyle = '135px'
    //   } else if (i === 2) {
    //     // this.getTableDataListtwo()
    //     this.topStyle = '7px'
    //   }
    // }
  }
}
</script>

<style scoped lang="scss">
.line {
  width: 100%;
  display: flex;
  flex-wrap: nowrap;
  .line-click {
    width: 90px;
    height: 30px;
    // background-color: aqua;
    display: flex;
    justify-content: center;
    align-items: center;
    border: snow 1px solid;
    border-radius: 50%;
    margin-bottom: 10px;
    margin-top: 5px;
    margin-left: 5px;
    cursor: pointer;
  }
}
.selectbut {
  position: absolute;
  // top: 85px;
  top: 10px;
  z-index: 99;
}
</style>
